import java.applet.Applet;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class RSA extends Applet {


	private static final BigInteger temp = new BigInteger("256");

	public String decrypt(String source, String b1, String b2) {
		BigInteger d = new BigInteger(b1);
		BigInteger n = new BigInteger(b2);

		List<Byte> byteList = new ArrayList<Byte>();

		String[] z = source.split(" ");
		for (int i = 0; i < z.length; i++) {
			BigInteger c = new BigInteger(z[i]);
			BigInteger a = c.modPow(d, n);

			BigInteger[] result;
			while ((result = a.divideAndRemainder(temp))[0]
					.compareTo(BigInteger.ZERO) == 1) {

				byteList.add((byte) result[1].intValue());
				a = result[0];
			}

			byteList.add((byte) a.intValue());
		}

		byte[] byteArray = new byte[byteList.size()];
		for (int i = 0; i < byteList.size(); i++) {
			byteArray[i] = byteList.get(i);
		}

		try {
			return new String(byteArray, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return source;
	}
}
